package com.scalar.chiptrack.adaptor.ikanos.ase;

import com.scalar.chiptrack.jobs.JobHandler;
import com.scalar.chiptrack.adaptor.AdaptorConstants;
import com.scalar.chiptrack.adaptor.AdaptorUtils;
import com.scalar.chiptrack.adaptor.InventoryLot;
import com.scalar.chiptrack.adaptor.ShippedLot;
import com.scalar.chiptrack.adaptor.FabSortLot;
import com.scalar.chiptrack.adaptor.TestLot;
import com.scalar.chiptrack.adaptor.TestLotBinReport;
import com.scalar.chiptrack.adaptor.SortLotBinData;
import com.scalar.chiptrack.adaptor.utils.Parser;
import com.scalar.chiptrack.adaptor.utils.ParserFactory;
import com.scalar.chiptrack.adaptor.utils.XLSParserImpl;
import com.scalar.chiptrack.adaptor.utils.ParserResult;
import com.scalar.chiptrack.adaptor.utils.CSVParserImpl;
import com.scalar.chiptrack.adaptor.dao.TestAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.InventoryLotDAO;
import com.scalar.chiptrack.adaptor.dao.FabSortAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.ShippedLotDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorRunInfo;
import com.scalar.chiptrack.utils.Logger;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.utils.DateUtil;
import com.scalar.ScalarException;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Date;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * User: ChandraSekhar
 * Date: Aug 26, 2008
 * Time: 6:50:04 PM
 */
public class ASETDataParser extends JobHandler implements AdaptorConstants
{
    private HashMap<String, InventoryLot> m_waferBankDataMap    = new HashMap<String, InventoryLot>();
    private HashMap<String, FabSortLot> m_sortDataMap           = new HashMap<String, FabSortLot>();
    private HashMap<String, ShippedLot> m_sortShipDataMap       = new HashMap<String, ShippedLot>();
    private HashMap<String, FabSortLot> m_sortBinDataMap        = new HashMap<String, FabSortLot>();
    private HashMap<String, FabSortLot> m_sortTotalMap          = new HashMap<String, FabSortLot>();

    private HashMap<String, InventoryLot> m_preTestDataMap      = new HashMap<String, InventoryLot>();
    private HashMap<String, TestLot> m_ftDataMap                = new HashMap<String, TestLot>();
    private HashMap<String, ShippedLot> m_testShipDataMap       = new HashMap<String, ShippedLot>();
    private HashMap<String, InventoryLot> m_eolDataMap          = new HashMap<String, InventoryLot>();
    private HashMap<String, InventoryLot> m_fgDataMap           = new HashMap<String, InventoryLot>();
    private HashMap<String, ShippedLot> m_fgShipDataMap         = new HashMap<String, ShippedLot>();

    private Logger m_parserLogger   = null;
    private String m_dataOutputDir  = null;


    public ASETDataParser() throws ScalarException
    {
        try
        {
            m_dataOutputDir = AdaptorUtils.getDataOutputDir( VENDOR_NAME_ASET, LOCATION_TYPE_TEST);
            AdaptorUtils.makeAllAdaptorDirs( m_dataOutputDir );
            m_parserLogger = AdaptorUtils.getDataParserLogger( m_dataOutputDir,VENDOR_NAME_ASET );
            TestAdaptorDAO.setLogger( m_parserLogger );
            InventoryLotDAO.setLogger(m_parserLogger);
            FabSortAdaptorDAO.setLogger(m_parserLogger);
            ShippedLotDAO.setLogger( m_parserLogger );
            AdaptorUtils.setLogger( m_parserLogger );
        }
        catch (ScalarException se)
        {
            log("ERROR!! ERROR!! ERROR!! Exception while loading ASET WIP output directory details from database, Exception: " + se);
            throw se;
        }
    }
    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main( String args[] ) throws Exception
    {
        try
        {
            new ASETDataParser().execute();
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /**
     *
     * @throws Exception
     */
    public void execute() throws Exception
    {
        AdaptorUtils.printHeader(VENDOR_NAME_ASET, CONSTANT_PARSER);

        File doneDestDir = new File(  m_dataOutputDir + "/done" );

        File sourceDataoutDir = new File( m_dataOutputDir );

        File[] fileList = sourceDataoutDir.listFiles();
        if ( ( fileList == null ) || ( fileList.length <= 3 ) )
        {
            log( "No file found in directory: " + sourceDataoutDir );
            throw new ScalarException( "\n+-----------No file found in directory " + sourceDataoutDir );
        }

        ArrayList successFileList = new ArrayList();

        boolean success = false;

        for ( int i = 0; i < fileList.length; i++ )
        {
            if ( fileList[i].isDirectory() == true )
            {
                continue;
            }

            try
            {
                // Step 1
                if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( ASETPOP3Adaptor.FILE_NAME_CWWIP_01 ) )
                {
                    // To parse the the ASET_WAFER_WIP_STATUS sheet in to table
                    ArrayList<ASETCPWipStatus> cpWipList = parseASETCPWipReport( fileList[i].getAbsolutePath() );

                    if ( cpWipList != null && cpWipList.size() > 0 )
                    {
                        //to get the ASET CP Wip Details details
                        getASETCPWipDetails( cpWipList );
                    }

                    successFileList.add( fileList[i] );
                }

                if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( ASETPOP3Adaptor.FILE_NAME_CTWIP_01 ) )
                {
                    parseFTWipReport( fileList[i].getAbsolutePath() );

                    successFileList.add( fileList[i] );
                }

                if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( ASETPOP3Adaptor.FILE_NAME_SHIP ) )
                {

                    parseASETShipReport( fileList[i].getAbsolutePath() );

                    /*if ( asetShipList != null && asetShipList.size() > 0 )
                    {
                        //to get the ASET SHip Details details
                        getASETShipDetails( asetShipList );
                    }*/
                    successFileList.add( fileList[i] );
                }
                if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( ASETPOP3Adaptor.FILE_NAME_TDRP ) )
                {
                    // To parse the the ASET_FG_WIP_STATUS sheet in to table
                    parseFGWipReport( fileList[i].getAbsolutePath() );

                    successFileList.add( fileList[i] );
                }
				if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( ASETPOP3Adaptor.FILE_NAME_HOLD ) )
                {
                    // To parse the the ASET HOLD Rpeort sheet in to table
                    parseFTHoldWipReport( fileList[i].getAbsolutePath() );

                    successFileList.add( fileList[i] );
                }
                if ( fileList[i].getName().startsWith( ASETPOP3Adaptor.FILE_NAME_YIELD )  || fileList[i].getName().indexOf( ASETPOP3Adaptor.FILE_NAME_YIELD )  != -1)
                {
                    ArrayList<TestLotBinReport> testBinList = parseFTBinReport( fileList[i].getAbsolutePath() );
                    if ( testBinList != null && testBinList.size() > 0 )
                    {
                        //to get the ASET Test Bin Details
                        if ( testBinList.isEmpty() == false )
                        {
                            log( "Updating ASET Binning Information" );
                            TestAdaptorDAO.saveTestBinInfo ( null, testBinList , VENDOR_NAME_ASET );
                            success = true;
                        }
                        else
                        {
                            log( "ASET Binning Information List is Empty" );
                        }
                    } 
                    //For Saving the Sort Binning
                    ArrayList<SortLotBinData> sortBinList = parseCPBinReport( fileList[i].getAbsolutePath() );

                    if ( sortBinList != null && sortBinList.size() > 0 )
                    {
                        log("updateing the ASET Cp Binning Info....");
                        FabSortAdaptorDAO.saveSortBinInfo( null, sortBinList, VENDOR_NAME_ASET );
                        success = true;
                    }

                    successFileList.add(fileList[i]);
                }
                success = true;
            }
            catch ( Exception e )
            {
                success = false;
                log( "Exception while parsing and storing file: " + fileList[i].getAbsolutePath() + "\nException: " + e );
                e.printStackTrace();
                throw e;
            }
        }
        /*Updating the Wafer Store Lot Information*/
        try
        {
            // Save Wafer Store Information
            if (m_waferBankDataMap.isEmpty() == false)
            {
                log(" Updating Wafer Store Lot Information");
                InventoryLotDAO.saveInventoryLot(null, m_waferBankDataMap.values().iterator(), LOCATION_TYPE_WAFER_BANK, VENDOR_NAME_ASET);
            }
            else
            {
                InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_WAFER_BANK, VENDOR_NAME_ASET);
            }
            success = true;
            m_waferBankDataMap.clear();
            m_waferBankDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log("ERROR!! ERROR!! ERROR!! Could not update Wafer Store Lot information into database: " + se);
            throw se;
        }

        try
        {
            if ( m_sortBinDataMap.isEmpty() == false )
            {
                FabSortAdaptorDAO.saveSortBinData( null, m_sortBinDataMap.values().iterator() );
            }
            success = true;
            m_sortBinDataMap.clear();
        }
        catch(Exception e)
        {
            success = false;
            System.out.println(" Exception Occrred While Saving the Sort Binning Info " +e );
            throw e;
        }
        //to saving sort Lot Info
        try
        {
            // Save Sort Information
            if ( m_sortDataMap.isEmpty() == false )
            {
                log( " Updating Sort Lot Information" );
                FabSortAdaptorDAO.saveSortLot( null, m_sortDataMap.values().iterator(), WIP_TYPE_SORT, VENDOR_NAME_ASET );
            }
            else
            {
                FabSortAdaptorDAO.closeFabSortLot( null, WIP_TYPE_SORT, VENDOR_NAME_ASET );
            }
            success = true;
            m_sortDataMap.clear();
            m_sortDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Sort Lot information into database: " + se );
            throw se;
        }

        try
        {
            // Save Sort Information
            if ( m_sortShipDataMap.isEmpty() == false )
            {
                log( " Updating Sort Shiping Lot Information" );
                ShippedLotDAO.saveShippedLot( null, m_sortShipDataMap.values().iterator() );
            }
            success = true;
            m_sortShipDataMap.clear();
            m_sortShipDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Sort Shipping Lot information into database: " + se );
            throw se;
        }
        // to save the Class Stroe lot tables
       try
       {
           if ( m_preTestDataMap.isEmpty() == false )
           {
               log(" Updating Class Stroe Lot Information");
               InventoryLotDAO.saveInventoryLot( null, m_preTestDataMap.values().iterator(), LOCATION_TYPE_PRE_TEST, VENDOR_NAME_ASET );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_PRE_TEST, VENDOR_NAME_ASET );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Class Stroe Lot information into database: " + se);
          throw se;
      }
        // Saving the Test Lot Information
        try
        {
            // Save Final Test Information
            if ( m_ftDataMap.isEmpty() == false )
            {

                log( " Updating Test Lot Information" );
                TestAdaptorDAO.saveTestLot( null, m_ftDataMap.values().iterator(), LOCATION_TYPE_FT, VENDOR_NAME_ASET );
            }
            else
            {
                TestAdaptorDAO.closeTestLot( null, LOCATION_TYPE_FT, VENDOR_NAME_ASET );
            }

            success = true;
            m_ftDataMap.clear();
            m_ftDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Test Lot information into database: " + se );
            throw se;
        }

        try
        {
            // Save Final Test Information
            if ( m_testShipDataMap.isEmpty() == false )
            {
                log( " Updating Test Shiping Lot Information" );
                ShippedLotDAO.saveShippedLot( null, m_testShipDataMap.values().iterator() );
            }
            success = true;
            m_testShipDataMap.clear();
            m_testShipDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Test Shipping Lot information into database: " + se );
            throw se;
        }

        try
        {
           if ( m_eolDataMap.isEmpty() == false )
           {
               log(" Updating EOL Class Stroe Lot Information");
               InventoryLotDAO.saveInventoryLot( null, m_eolDataMap.values().iterator(), LOCATION_TYPE_EOL, VENDOR_NAME_ASET );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_EOL, VENDOR_NAME_ASET  );
           }
        }
        catch (ScalarException se)
        {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update EOL Class Stroe Lot information into database: " + se);
          throw se;
        }
        // to save the Finished Goods lot tables
       try
       {
           if ( m_fgDataMap.isEmpty() == false )
           {
               log(" Updating Finished Goods Lot Information");
               InventoryLotDAO.saveInventoryLot( null, m_fgDataMap.values().iterator(), LOCATION_TYPE_FG, VENDOR_NAME_ASET );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_FG, VENDOR_NAME_ASET );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Finished Goods Lot information into database: " + se);
          throw se;
      }

        try
        {
            // Save FG Shipping Information
            if ( m_fgShipDataMap.isEmpty() == false )
            {
                log( " Updating FG Shiping Lot Information" );
                ShippedLotDAO.saveShippedLot( null, m_fgShipDataMap.values().iterator() );
            }
            success = true;
            m_fgShipDataMap.clear();
            m_fgShipDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update FG Shipping Lot information into database: " + se );
            throw se;
        }

        // To Close the Drop Out Lots
        AdaptorDAO.closeDropOutLots(VENDOR_NAME_ASET);

         // TO SEND THE NEW LOTS, NEW TRANSIT LOTS, NO PO LOTS, DISCREPANCY LOTS NOTIFICATIONS TO THE USER
        AdaptorDAO.sendAllNotifications(VENDOR_NAME_ASET, true, true, true);


        int adaptor_id = AdaptorRunInfo.getLastRunAdaptorId( ASETPOP3Adaptor.ADAPTOR_NAME, CONSTANT_ADAPTOR);

        // Update Adaptor_Run_Info table
        try
        {
            if ( success == true )
            {
                AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, ASETPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
                System.out.println( "SUCCESSFULLY UPDATED IN THE DATABASE" );
            }
        }
        catch ( ScalarException se )
        {
            success = false; //As filES DATA SAVED , UPDATEING AS SUCCESS
            AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, ASETPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
            log( "WARNING!! WARNING!! WARNING!! Could not update Adaptor run information, Exception: " + se );
            throw se;
        }
        // Move the successful files to 'done' directory
       if ( success )
       {
           AdaptorUtils.moveFilesToDone( successFileList, doneDestDir );
       }
    }



    private ArrayList<ASETCPWipStatus> parseASETCPWipReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ArrayList wipList              = new ArrayList();
        String line                     = null;

        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for ASET CP Wip Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for ASET CP Wip Report..." );

            BufferedReader reader = new BufferedReader( new FileReader( detailWipFile ) );
            reader.readLine();  // Read out <Header Info > Line
            reader.readLine();
            reader.readLine();
            reader.readLine();
            reader.readLine();

            while ( ( line = reader.readLine() ) != null  )
            {
                ASETCPWipStatus wipStatus = new ASETCPWipStatus();

                line = line.replaceAll( "\"", "" );
                String[] token = line.split( "\t" );

                if ( token.length > 15 )
                {
                    for (int x = 0; x < token.length; x++)
                    {
                        if (token[x] != null && token[x].trim().length() > 0   )
                        {
                            switch (x)
                            {
                                case 0:
                                        wipStatus.setLotType( token[x].trim() );
                                        break;
                                case 1:
                                        wipStatus.setReleaseNo( token[x].trim() );
                                        break;
                                case 2:
                                        wipStatus.setReceiveDate( StringUtils.formatDate(token[x].trim(), "yyyyMMdd", "MM/dd/yyyy" ) );
                                        break;
                                case 3:
                                        wipStatus.setIssueDate( StringUtils.formatDate(token[x].trim(), "yyyyMMdd", "MM/dd/yyyy" ) );
                                        break;
                                case 4:
                                        wipStatus.setDeviceName( token[x].trim() );
                                        break;
                                case 5:
                                        wipStatus.setFabLotNumber( token[x].trim());
                                        break;
                                case 6:
                                        wipStatus.setLotStatus( token[x].trim() );
                                        break;
                                case 7:
                                        wipStatus.setLotNumber( token[x].trim() );
                                        break;
                                case 8:
                                        wipStatus.setReceiveQty( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 9:
                                        wipStatus.setIntraQty ("0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 10:
                                        wipStatus.setUnIssueQty( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim()  );
                                        break;
                                case 11:
                                        wipStatus.setIssuedQty ("0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 12:
                                        wipStatus.setCpXp( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim()  );
                                        break;
                                case 13:
                                        wipStatus.setCpXs( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 14:
                                        wipStatus.setCp1( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 15:
                                        wipStatus.setCp2( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 16:
                                        wipStatus.setLr1( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 17:
                                        wipStatus.setLr2( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 18:
                                        wipStatus.setHold( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 19:
                                        wipStatus.setIk( "0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 20:
                                        wipStatus.setQa("0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 21:
                                        wipStatus.setWp("0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 22:
                                        wipStatus.setElseQty("0".equalsIgnoreCase(token[x].trim() ) ? null : token[x].trim() );
                                        break;
                                case 23:
                                        wipStatus.setExpectedDate(StringUtils.formatDate(token[x].trim(), "yyyyMMdd", "MM/dd/yyyy" ));
                                        break;

                                }
                          }
                    }

                    if ( wipStatus.getDeviceName() != null && wipStatus.getDeviceName().length() >0
                         && wipStatus.getFabLotNumber() != null && wipStatus.getFabLotNumber().length() >0 )
                    {
                        wipList.add( wipStatus );
                    }
                }
            }

            try
            {
                if ( reader != null )
                {
                   reader.close();
                }
            }
            catch(IOException ignore)
            {
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET CP Wip Report");
            ex.printStackTrace();
            throw ex;
        }

        return wipList;

    } // end of prase ASET CP Wip Report method

    private void parseASETShipReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ParserResult result     = null;
        ShippedLot shippedLot   = null;
        String partNumber       = null;
        String lotNumber        = null;
        String fabLotNumber     = null;
        String shipDate         = null;
        String nextLocation     = null;
        String dropShipNo       = null;

        try
        {
            File shipFile = new File( fileName );
            if ( shipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for ASET Ship Info..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for ASET Ship Info..." );

            Parser parser = ParserFactory.getXLSParser( shipFile , 1 );

            ((XLSParserImpl)parser).setHeaderRowIdx(1);
            ((XLSParserImpl)parser).setDataStartRowIdx(2);

            result = parser.parse();

            while ( result.next() )
            {
                partNumber = result.getString("TARGET_DEVICE");
                lotNumber  = result.getString("SCHEDULE");
                fabLotNumber = result.getString("LOTNO");
                if ( lotNumber == null )
                {
                    lotNumber = fabLotNumber;
                }

                if ( partNumber != null && partNumber.trim().length() > 0 && lotNumber != null && lotNumber.trim().length() >0  )
                {
                    if ( result.getString("SHIPDATE") != null )
                    {
                        shipDate = StringUtils.formatDate ( result.getString("SHIPDATE"), "yyyyMMdd", "MM/dd/yyyy");
                    }
                    nextLocation = result.getString("NEXTLOC");
                    int quantity = 0;
                    int shipDieQty = 0;
                    if ( result.getString("MATERIAL") != null &&  "W".equalsIgnoreCase(result.getString("MATERIAL") ) )
                    {
						if ( partNumber.endsWith("-00") )
                            {
                                partNumber = partNumber.substring(0, partNumber.lastIndexOf("-00") );
                            }
  
                        shippedLot = (ShippedLot) m_sortShipDataMap.get( partNumber + fabLotNumber + shipDate + nextLocation  );

                        if (shippedLot == null)
                        {
                            shippedLot = new ShippedLot(VENDOR_NAME_ASET, LOCATION_TYPE_SORT );
                            m_sortShipDataMap.put(partNumber + fabLotNumber + shipDate+ nextLocation , shippedLot);
                        }
                        shippedLot.setProcessType( LOCATION_TYPE_SORT );
                        if ( shippedLot.getShipQty() != null )
                        {
                           try
                           {
                               quantity = Integer.parseInt( shippedLot.getShipQty() );
                           }
                           catch ( NumberFormatException ignore )
                           {
                               quantity = 0;
                           }
                           quantity += result.getInt("WAFER_PIECES");
                           shipDieQty += result.getInt("SHIP_DIE_QTY");

                        }
                        else
                        {
                           quantity = result.getInt("WAFER_PIECES");
                           shipDieQty = result.getInt("SHIP_DIE_QTY");
                        }
                    }
                    else
                    {
                        dropShipNo = result.getString("Drop Ship No");

                        shippedLot = (ShippedLot) m_fgShipDataMap.get( partNumber + fabLotNumber+ lotNumber + shipDate + nextLocation + dropShipNo );

                        if (shippedLot == null)
                        {
                            shippedLot = new ShippedLot(VENDOR_NAME_ASET, LOCATION_TYPE_FINISHED_GOODS );
                            m_fgShipDataMap.put(partNumber + fabLotNumber+ lotNumber + shipDate+ nextLocation + dropShipNo, shippedLot);
                        }
                        shippedLot.setProcessType( LOCATION_TYPE_FG );
                        if ( shippedLot.getShipQty() != null )
                        {
                           try
                           {
                               quantity = Integer.parseInt( shippedLot.getShipQty() );
                           }
                           catch ( NumberFormatException ignore )
                           {
                               quantity = 0;
                           }
                           quantity += result.getInt("SHIP_DIE_QTY");

                        }
                        else
                        {
                           quantity = result.getInt("SHIP_DIE_QTY");
                        }
                    }
                    if ( quantity > 0 )
                    {
                        shippedLot.setPartNumber( partNumber );
                        shippedLot.setShipDate( shipDate );
                        if ( LOCATION_TYPE_SORT.equalsIgnoreCase( shippedLot.getProcessType() ) )
                       {
                           shippedLot.setShipQty( quantity + "" );
                           shippedLot.setShipDieQty(shipDieQty + "" );
                           shippedLot.setLotNumber( fabLotNumber );
						   shippedLot.setCustomerPO( result.getString("CUSTPO") );

                       }
                       else
                       {
                          shippedLot.setShipQty( quantity + "" );
                          shippedLot.setLotNumber( lotNumber );
						  shippedLot.setCustomerPO( result.getString("DROPSHIP CUSTPO") );
                       }
                        shippedLot.setShipQty( quantity + "");
                        shippedLot.setShippingDoc( dropShipNo );
                        shippedLot.setMawb( result.getString("MAWB") );
                        shippedLot.setHawb( result.getString("HAWB") );
                        shippedLot.setCustomerSO( result.getString("SO NO") );
                        shippedLot.setInvoiceNumber( result.getString("INVOICENO"));
                        shippedLot.setFlightNumber( result.getString("FLTNO"));
                        shippedLot.setEta( StringUtils.formatDate( result.getString("ETA"), "yyyyMMdd", "MM/dd/yyyy") );
                        shippedLot.setEtd( StringUtils.formatDate( result.getString("ETD"), "yyyyMMdd", "MM/dd/yyyy") );
                        shippedLot.setNextLocation( nextLocation );
                        shippedLot.setFabLotNumber( fabLotNumber );
                    }
                }
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET SHIP sheet");
            ex.printStackTrace();
            throw ex;
        }

    }// end of prase Shipment Report method

    private void getASETCPWipDetails ( ArrayList cpWipLotsList ) throws Exception
    {
       ASETCPWipStatus wipStatus  = null;
       InventoryLot inventoryLot  = null;
       FabSortLot sortLot         = null;
       String lotNumber        = null;
       String partNumber       = null;
       String fabLotNumber     = null;


       if ( cpWipLotsList == null || cpWipLotsList.size() <= 0 )
        {
            return;
        }

        try
        {
            Iterator iterator = cpWipLotsList.iterator();

            while (iterator.hasNext())
            {
                wipStatus = (ASETCPWipStatus) iterator.next();

                fabLotNumber = wipStatus.getFabLotNumber();
                partNumber = wipStatus.getDeviceName();
                lotNumber  = wipStatus.getLotNumber(); //schedule No
                String lotStatus = null;
                if( wipStatus.getLotStatus() != null  )
                {
                    lotStatus = LOT_STATUS_HOLD;
                }
                else
                {
                    lotStatus = LOT_STATUS_RUNNING;
                }

                if ( fabLotNumber != null && fabLotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    //Wafer STORE LOTS
                    if ( wipStatus.getIntraQty() != null  || wipStatus.getUnIssueQty() != null )
                    {
                        log("In Wafer Store " + lotNumber );
                        inventoryLot = (InventoryLot) m_waferBankDataMap.get( partNumber + fabLotNumber );
                        if ( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_ASET, LOCATION_TYPE_WAFER_STORE );
                            m_waferBankDataMap.put( partNumber + fabLotNumber, inventoryLot );
                        }

                        if ( wipStatus.getIntraQty() != null )
                        {
                            inventoryLot = (InventoryLot) m_waferBankDataMap.get( partNumber + fabLotNumber );

                            if (inventoryLot.getWaferQtyIn() != null)
                            {
                               try
                                {
                                    inventoryLot.setWaferQtyIn( ( Integer.parseInt( inventoryLot.getWaferQtyIn() ) + Integer.parseInt( wipStatus.getIntraQty() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setWaferQtyIn( wipStatus.getIntraQty() );
                                }
                            }
                            else
                            {
                                inventoryLot.setWaferQtyIn( wipStatus.getIntraQty());
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage ( inventoryLot.getStage() +", IN_TR") ;
                            }
                            else
                            {
                                inventoryLot.setStage("IN_TR");
                            }
                        }
                        if ( wipStatus.getUnIssueQty() != null )
                        {
                            inventoryLot = (InventoryLot) m_waferBankDataMap.get( partNumber + fabLotNumber );

                            if (inventoryLot.getWaferQtyIn() != null)
                            {
                               try
                                {
                                    inventoryLot.setWaferQtyIn( ( Integer.parseInt( inventoryLot.getWaferQtyIn() ) + Integer.parseInt( wipStatus.getUnIssueQty() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setWaferQtyIn( wipStatus.getUnIssueQty() );
                                }
                            }
                            else
                            {
                                inventoryLot.setWaferQtyIn( wipStatus.getUnIssueQty());
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage ( inventoryLot.getStage() +", Un Issue") ;
                            }
                            else
                            {
                                inventoryLot.setStage("Un Issue");
                            }
                        }

                        if ( inventoryLot.getWaferQtyIn() != null )
                        {
                            inventoryLot.setLotNumber( fabLotNumber );
                            inventoryLot.setVendorLot( lotNumber );
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setStatus( lotStatus );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );

                            inventoryLot.setDateIn( wipStatus.getReceiveDate() );
                        }
                    }

                    //SORT
                    if( wipStatus.getCpXp() != null || wipStatus.getCpXs() != null || wipStatus.getCp1() != null || wipStatus.getCp1() != null || wipStatus.getCp2() != null
                            || wipStatus.getLr1() != null || wipStatus.getLr2() != null || wipStatus.getHold() != null || wipStatus.getIk() != null
                            || wipStatus.getQa() != null || wipStatus.getWp() != null || wipStatus.getElseQty() != null )
                    {
                        log( "In Sort " + fabLotNumber ) ;

                        sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                        if (sortLot == null)
                        {
                            sortLot = new FabSortLot( VENDOR_NAME_ASET, WIP_TYPE_SORT );
                            m_sortDataMap.put( partNumber + fabLotNumber, sortLot);
                        }

                        if ( wipStatus.getCpXp() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getCpXp() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getCpXp() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getCpXp() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", CP PreTest") ;
                            }
                            else
                            {
                                sortLot.setStage("CP PreTest");
                            }
                        }
                        if ( wipStatus.getCpXs() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getCpXs() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getCpXs() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getCpXs() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", CP Sample") ;
                            }
                            else
                            {
                                sortLot.setStage("CP Sample");
                            }
                        }
                        if ( wipStatus.getCp1() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getCp1() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getCp1() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getCp1() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", CP1") ;
                            }
                            else
                            {
                                sortLot.setStage("CP1");
                            }
                        }
                        if ( wipStatus.getCp2() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getCp2() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getCp2() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getCp2() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", CP2") ;
                            }
                            else
                            {
                                sortLot.setStage("CP2");
                            }
                        }
                        if ( wipStatus.getLr1() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getLr1() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getLr1() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getLr1() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", TRIM 1 Sample") ;
                            }
                            else
                            {
                                sortLot.setStage("TRIM 1 Sample");
                            }
                        }
                        if ( wipStatus.getLr2() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getLr2() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getLr2() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getLr2() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", TRIM 2 Sample") ;
                            }
                            else
                            {
                                sortLot.setStage("TRIM 2 Sample");
                            }
                        }
                        if ( wipStatus.getHold() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getHold() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getHold() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getHold() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", Hold") ;
                            }
                            else
                            {
                                sortLot.setStage("Hold");
                            }
                        }
                        if ( wipStatus.getIk() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getIk() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getIk() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getIk() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", INK + BAKE + WASH") ;
                            }
                            else
                            {
                                sortLot.setStage("INK + BAKE + WASH");
                            }
                        }
                        if ( wipStatus.getQa() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getQa() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getQa() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getQa() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", INSPECTION QA GATE") ;
                            }
                            else
                            {
                                sortLot.setStage("INSPECTION QA GATE");
                            }
                        }
                        if ( wipStatus.getWp() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getWp() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getWp() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getWp() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", PACKING + MAPPING") ;
                            }
                            else
                            {
                                sortLot.setStage("PACKING + MAPPING");
                            }
                        }
                        if ( wipStatus.getElseQty() != null  )
                        {
                            sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                            if (sortLot.getQtyIn() != null)
                            {
                               try
                                {
                                    sortLot.setQtyIn( ( Integer.parseInt( sortLot.getQtyIn() ) + Integer.parseInt( wipStatus.getElseQty() ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    sortLot.setQtyIn( wipStatus.getElseQty() );
                                }
                            }
                            else
                            {
                                sortLot.setQtyIn( wipStatus.getElseQty() );
                            }
                            if ( sortLot.getStage() != null )
                            {
                                sortLot.setStage ( sortLot.getStage() +", WAIT FOR CLOSE") ;
                            }
                            else
                            {
                                sortLot.setStage("WAIT FOR CLOSE");
                            }
                        }
                        if ( sortLot.getQtyIn() != null )
                        {
                            sortLot.setLotId( fabLotNumber );
                            sortLot.setCustProduct( partNumber );
                            sortLot.setFabLotNumber( fabLotNumber );

                            sortLot.setLotCategory ( LOT_CATEGORY_TYPE_PROD );
                            if ( wipStatus.getIssueDate()  != null && wipStatus.getIssueDate().length() > 8 )
                            {
                                sortLot.setDateIn( wipStatus.getIssueDate() ) ;
                            }
                            else
                            {
                                sortLot.setDateIn( wipStatus.getReceiveDate() ) ;
                            }
                            if ( wipStatus.getExpectedDate() != null && wipStatus.getExpectedDate().length() > 8 )
                            {
                                sortLot.setForcastedDateOut( wipStatus.getExpectedDate() );
                            }
                            sortLot.setLotStatus( lotStatus );
                        }
                    }
                }
            }
        }
        catch( Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the ASET Wafer Store & Sort Wip Data Details........" + e );
            e.printStackTrace();
            throw e;
        }
    }

    private void parseFGWipReport(String fileName) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );
        InventoryLot inventoryLot = null;
        String lotNumber        = null;
        String partNumber       = null;
        String fablotNumber     = null;
        ParserResult result     = null ;

        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for ASET FG Wip Info..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for ASET FG Wip Info..." );

            Parser parser = ParserFactory.getCSVParser( detailWipFile , '\t' );

            ((CSVParserImpl)parser).setHeaderRowIdx(4);
            ((CSVParserImpl)parser).setDataStartRowIdx(5);

            result = parser.parse();

            while ( result.next() )
            {
                fablotNumber    = result.getString("LOT  NO");
                partNumber      = result.getString("DEVICE TYPE");
                lotNumber       = result.getString("SCHD_NO");

                if( lotNumber == null )
                {
                    lotNumber = fablotNumber;
                }

                if ( lotNumber != null && lotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    log( "In FG " + lotNumber );

                    inventoryLot = (InventoryLot) m_fgDataMap.get( partNumber + lotNumber + fablotNumber);

                    if (inventoryLot == null)
                    {
                        inventoryLot = new InventoryLot(VENDOR_NAME_ASET, LOCATION_TYPE_FG );
                        m_fgDataMap.put( partNumber + lotNumber + fablotNumber, inventoryLot);
                    }
                    int quantity = 0;
                    if (inventoryLot.getQtyIn() != null)
                    {
                        try
                        {
                            quantity = Integer.parseInt(inventoryLot.getQtyIn());
                        }
                        catch (NumberFormatException ignore) {
                        }
                        quantity += result.getInt("Bal Good");
                    }
                    else
                    {
                       quantity = result.getInt("Bal Good");
                    }

                    if ( quantity > 0 )
                    {
                        inventoryLot.setLotNumber( lotNumber );
                        inventoryLot.setPartNumber( partNumber );
                        inventoryLot.setStatus( LOT_STATUS_RUNNING );
                        inventoryLot.setFabLotNumber( fablotNumber );
                        inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                        if (result.getString("Close Date") != null )
                        {
                            inventoryLot.setDateIn( StringUtils.formatDate(result.getString("Close Date"), "yyyyMMdd", "MM/dd/yyyy"));
                        }
                        else
                        {
                            inventoryLot.setDateIn( DateUtil.formatDate(new Date(), "MM/dd/yyyy") );
                        }
                        inventoryLot.setQtyIn( quantity +"");
                        inventoryLot.setDateCode( result.getString("Date Code") );
                        inventoryLot.setPkgType( result.getString("PKG") );
                        inventoryLot.setLeadCount( result.getString("L/C") );
                    }
                }
            }
        }
        catch( Exception e)
        {
            System.out.println(" !!ERROR !! ERROR Exception while get getting the ASET FG Wip Details");
            e.printStackTrace();
            throw e;
        }
    }

    private void parseFTWipReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ParserResult result            = null;
        TestLot testLot         = null;
        InventoryLot inventoryLot = null;
        String lotNumber        = null;
        String partNumber       = null;
        String fablotNumber     = null;
        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for FT Wip Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for FT Wip Report..." );

             Parser parser = ParserFactory.getCSVParser( detailWipFile, '\t' );

            ((CSVParserImpl)parser).setHeaderRowIdx(5);
            ((CSVParserImpl)parser).setDataStartRowIdx(6);

            result = parser.parse();
            
            while ( result.next() )
            {
                partNumber = result.getString("DEVICE");
                fablotNumber = result.getString("LOT_NO");
                lotNumber   =  result.getString("SCHEDULE");
                if ( lotNumber == null )
                {
                    lotNumber = fablotNumber;
                }
                if (partNumber!= null && partNumber.trim().length()>0 && lotNumber != null && lotNumber.trim().length() > 0 )
                {
                    //PRE TEST
                    if ( result.getString("IN_TRA") != null && !"0".equalsIgnoreCase( result.getString("IN_TRA") )
                         || result.getString("UN_ISS") != null && !"0".equalsIgnoreCase( result.getString("UN_ISS") )   )
                    {
                        inventoryLot = (InventoryLot)m_preTestDataMap.get( partNumber + lotNumber + fablotNumber );

                        if ( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot( VENDOR_NAME_ASET, LOCATION_TYPE_PRE_TEST );
                            m_preTestDataMap.put( partNumber + lotNumber + fablotNumber, inventoryLot );
                        }

                        if( result.getString("IN_TRA") != null && !"0".equalsIgnoreCase( result.getString("IN_TRA") ) )
                       {
                           inventoryLot = (InventoryLot)m_preTestDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("IN_TRA") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("IN_TRA") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("IN_TRA") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", IN_TRA");
                            }
                            else
                            {
                                inventoryLot.setStage("IN_TRA");
                            }
                        }
                        if( result.getString("UN_ISS") != null && !"0".equalsIgnoreCase( result.getString("UN_ISS") ) )
                        {
                           inventoryLot = (InventoryLot)m_preTestDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("UN_ISS") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("UN_ISS") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("UN_ISS") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", UN_ISS");
                            }
                            else
                            {
                                inventoryLot.setStage("UN_ISS");
                            }
                        }

                         if ( inventoryLot.getQtyIn() != null && !"0".equalsIgnoreCase(inventoryLot.getQtyIn() ) )
                         {
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setLotNumber( lotNumber );
                            if ( result.getDate("REC_DATE", "yyMMdd") != null )
                            {
                                inventoryLot.setDateIn( StringUtils.formatDateToString(result.getDate("REC_DATE", "yyMMdd"), "MM/dd/yyyy" ) );
                            }
                            else 
                            {
                                inventoryLot.setDateIn( StringUtils.formatDateToString(new Date(), "MM/dd/yyyy" ) );
                            }
                            inventoryLot.setFabLotNumber( fablotNumber );
                            inventoryLot.setPkgType( result.getString("PKG") );
                            inventoryLot.setLeadCount( result.getString("L/C") );
                            inventoryLot.setCustomerPO( result.getString("RELEASE_NO"));
                             if ( result.getString("HLD") != null )
                             {
                                inventoryLot.setStatus( LOT_STATUS_HOLD );
                             }
                             else
                             {
                                 inventoryLot.setStatus( LOT_STATUS_RUNNING );
                             }
                            if ( result.getString("lot_type") == null || "p".equalsIgnoreCase(result.getString("lot_type")) )
                            {
                                inventoryLot.setLotCategory( LOT_CATEGORY_TYPE_PROD );
                            }
                            else
                            {
                                inventoryLot.setLotCategory( LOT_CATEGORY_TYPE_ENGG );
                            }
                        }
                    }

                    // FT Process  PT_BUFF, PT, BI,T1,T2 ,TX,Hold
                    if ( result.getString("PT_BUFF") != null && !"0".equalsIgnoreCase( result.getString("PT_BUFF") )
                        || result.getString("PT") != null && !"0".equalsIgnoreCase( result.getString("PT") )
                        || result.getString("BI") != null && !"0".equalsIgnoreCase( result.getString("BI") )    
                        || result.getString("T1") != null && !"0".equalsIgnoreCase( result.getString("T1") )
                        || result.getString("T2") != null && !"0".equalsIgnoreCase( result.getString("T2") )
                        || result.getString("TX") != null && !"0".equalsIgnoreCase( result.getString("TX") )
                        || result.getString("HOLD") != null && !"0".equalsIgnoreCase( result.getString("HOLD") )  )
                    {
                        log(lotNumber + "In Test FT");

                        testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                        if (testLot == null)
                        {
                            testLot = new TestLot(VENDOR_NAME_ASET);
                            m_ftDataMap.put(partNumber + lotNumber + fablotNumber, testLot);
                        }

                       // FOR SETTING THE QTY IN

                       if( result.getString("PT_BUFF") != null && !"0".equalsIgnoreCase( result.getString("PT_BUFF") ) )
                       {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("PT_BUFF") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("PT_BUFF") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("PT_BUFF") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", PT_BUFF");
                            }
                            else
                            {
                                testLot.setStage("PT_BUFF");
                            }
                        }
                        if( result.getString("PT") != null && !"0".equalsIgnoreCase( result.getString("PT") ) )
                        {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("PT") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("PT") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("PT") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", PT");
                            }
                            else
                            {
                                testLot.setStage("PT");
                            }
                        }
                       if( result.getString("T1") != null && !"0".equalsIgnoreCase( result.getString("T1") ) )
                       {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("T1") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("T1") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("T1") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", FT1");
                            }
                            else
                            {
                                testLot.setStage("FT1");
                            }
                        }
                       if( result.getString("T2") != null && !"0".equalsIgnoreCase( result.getString("T2") ) )
                       {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("T2") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("T2") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("T2") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", FT2");
                            }
                            else
                            {
                                testLot.setStage("FT2");
                            }
                        }
                       if( result.getString("TX") != null && !"0".equalsIgnoreCase( result.getString("TX") ))
                       {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("TX") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("TX") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("TX") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", TX");
                            }
                            else
                            {
                                testLot.setStage("TX");
                            }
                        }
                       if( result.getString("BI") != null && !"0".equalsIgnoreCase( result.getString("BI") ))
                       {
                           testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( testLot.getQtyIn() != null )
                           {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("BI") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("BI") );
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getString("BI") );
                            }
                            if ( testLot.getStage() != null )
                            {
                                testLot.setStage( testLot.getStage() + ", BI");
                            }
                            else
                            {
                                testLot.setStage("BI");
                            }
                        }
                        if( result.getString("HOLD") != null && !"0".equalsIgnoreCase( result.getString("HOLD") ) )
                        {
                            testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + Integer.parseInt( result.getString("HOLD") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getString("HOLD") );
                                }
                             }
                             else
                             {
                                testLot.setQtyIn( result.getString("HOLD") );
                             }
                             if ( testLot.getStage() != null )
                             {
                                testLot.setStage( testLot.getStage() + ", FTHold");
                             }
                             else
                             {
                                testLot.setStage("FTHold");
                             }
                        }

                        if ( testLot.getQtyIn() != null && !"0".equalsIgnoreCase(testLot.getQtyIn() ) )
                        {
                            testLot.setPartNumber( partNumber );
                            testLot.setLotNumber( lotNumber );
                            testLot.setFabLotNumber( fablotNumber );
                            if ( result.getDate("ISSUE", "yyMMdd") != null )
                            {
                                testLot.setDateIn( StringUtils.formatDateToString(result.getDate("ISSUE", "yyMMdd"), "MM/dd/yyyy" ) );
                            }
                            else if (result.getDate("REC_DATE", "yyMMdd") != null)
                            {
                                testLot.setDateIn( StringUtils.formatDateToString(result.getDate("REC_DATE", "yyMMdd"), "MM/dd/yyyy" ) );
                            }
                            if (result.getDate("SOD", "yyyyMMdd") != null  )
                            {
                                testLot.setExpecetedDate( StringUtils.formatDateToString(result.getDate("SOD", "yyyyMMdd"), "MM/dd/yyyy" ) );
                            }

                            testLot.setLeadCount( result.getString("L/C") );
                            testLot.setPackageType( result.getString("PKG") );
                            testLot.setPoNumber( result.getString("RELEASE_NO"));
                            if ( result.getString("HLD") != null )
                            {
                               testLot.setStatus(LOT_STATUS_HOLD);
                            }
                            else
                            {
                               testLot.setStatus(LOT_STATUS_RUNNING);
                            }
                            testLot.setPsType( LOCATION_TYPE_FT );
                            if ( result.getString("lot_type") == null || "p".equalsIgnoreCase(result.getString("lot_type")) )
                            {
                                testLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            }
                            else
                            {
                                testLot.setCategory( LOT_CATEGORY_TYPE_ENGG );
                            }
                        }
                    }

                    // EOL Process   TM,VM, BK, TR, PK, FT Else
                    if ( result.getString("TM") != null && !"0".equalsIgnoreCase( result.getString("TM") )
                        || result.getString("VM") != null && !"0".equalsIgnoreCase( result.getString("VM") )
                        || result.getString("BK") != null && !"0".equalsIgnoreCase( result.getString("BK") )
                        || result.getString("TR") != null && !"0".equalsIgnoreCase( result.getString("TR") )
                        || result.getString("PK") != null && !"0".equalsIgnoreCase( result.getString("PK") )
                        || result.getString("ELSE") != null && !"0".equalsIgnoreCase( result.getString("ELSE") )  )
                    {
                        log(lotNumber + "In EOL");

                        inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                        if (inventoryLot == null)
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_ASET, LOCATION_TYPE_EOL);
                            m_eolDataMap.put(partNumber + lotNumber + fablotNumber, inventoryLot);
                        }

                       // FOR SETTING THE QTY IN
                       if( result.getString("TM") != null && !"0".equalsIgnoreCase( result.getString("TM") ) )
                       {
                           inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("TM") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("TM") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("TM") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", TM");
                            }
                            else
                            {
                                inventoryLot.setStage("TM");
                            }
                        }

                        if( result.getString("VM") != null && !"0".equalsIgnoreCase( result.getString("VM") ) )
                        {
                           inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("VM") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("VM") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("VM") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", VM");
                            }
                            else
                            {
                                inventoryLot.setStage("VM");
                            }
                        }
                        if( result.getString("BK") != null && !"0".equalsIgnoreCase( result.getString("BK") ) )
                        {
                            inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                            if( inventoryLot.getQtyIn() != null )
                            {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("BK") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("BK") );
                                }
                             }
                             else
                             {
                                inventoryLot.setQtyIn( result.getString("BK") );
                             }
                             if ( inventoryLot.getStage() != null )
                             {
                                inventoryLot.setStage( inventoryLot.getStage() + ", Baking");
                             }
                             else
                             {
                                inventoryLot.setStage("Baking");
                             }
                        }
                       if( result.getString("TR") != null && !"0".equalsIgnoreCase( result.getString("TR") ) )
                       {
                           inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("TR") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("TR") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("TR") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", TR");
                            }
                            else
                            {
                                inventoryLot.setStage("TR");
                            }
                        }
                        if( result.getString("PK") != null && !"0".equalsIgnoreCase( result.getString("PK") ) )
                        {
                            inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                            if( inventoryLot.getQtyIn() != null )
                            {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("PK") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("PK") );
                                }
                             }
                             else
                             {
                                inventoryLot.setQtyIn( result.getString("PK") );
                             }
                             if ( inventoryLot.getStage() != null )
                             {
                                inventoryLot.setStage( inventoryLot.getStage() + ", Paking");
                             }
                             else
                             {
                                inventoryLot.setStage("Paking");
                             }
                        }
                        if( result.getString("ELSE") != null && !"0".equalsIgnoreCase( result.getString("ELSE") ) )
                        {
                           inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fablotNumber );
                           if( inventoryLot.getQtyIn() != null )
                           {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + Integer.parseInt( result.getString("ELSE") ) ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getString("ELSE") );
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getString("ELSE") );
                            }
                            if ( inventoryLot.getStage() != null )
                            {
                                inventoryLot.setStage( inventoryLot.getStage() + ", FtElse");
                            }
                            else
                            {
                                inventoryLot.setStage("FtElse");
                            }
                        }

                        if ( inventoryLot.getQtyIn() != null && !"0".equalsIgnoreCase(inventoryLot.getQtyIn() ) )
                        {
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setLotNumber( lotNumber );
                            inventoryLot.setFabLotNumber( fablotNumber );
                            if ( result.getDate("ISSUE", "yyMMdd") != null )
                            {
                                inventoryLot.setDateIn( StringUtils.formatDateToString(result.getDate("ISSUE", "yyMMdd"), "MM/dd/yyyy" ) );
                            }
                            else if (result.getDate("REC_DATE", "yyMMdd") != null)
                            {
                                inventoryLot.setDateIn( StringUtils.formatDateToString(result.getDate("REC_DATE", "yyMMdd"), "MM/dd/yyyy" ) );
                            }
                            if (result.getDate("SOD", "yyyyMMdd") != null  )
                            {
                                inventoryLot.setExpectedDate( StringUtils.formatDateToString(result.getDate("SOD", "yyyyMMdd"), "MM/dd/yyyy" ) );
                            }
                            inventoryLot.setPkgType( result.getString("PKG") );
                            inventoryLot.setLeadCount( result.getString("L/C") );
                            if ( result.getString("HLD") != null )
                            {
                               inventoryLot.setStatus(LOT_STATUS_HOLD);
                            }
                            else
                            {
                               inventoryLot.setStatus(LOT_STATUS_RUNNING);
                            }
                            inventoryLot.setCustomerPO( result.getString("RELEASE_NO"));
                            if ( result.getString("lot_type") == null || "p".equalsIgnoreCase(result.getString("lot_type")) )
                            {
                                inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            }
                            else
                            {
                                inventoryLot.setCategory( LOT_CATEGORY_TYPE_ENGG );
                            }
                        }
                    } //END OF EOL
                } //Part number Null checking
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET FT Wip Report");
            ex.printStackTrace();
            throw ex;
        }
    } // end of prase FT Wip Report method

	private void parseFTHoldWipReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );
        ParserResult result     = null;

        String lotNumber        = null;
        String partNumber       = null;
        String fablotNumber     = null;
        TestLot testLot         = null;
        FabSortLot sortLot      = null;
        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for Ft Hold Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for FT Hold Report..." );

            Parser parser = ParserFactory.getXLSParser( detailWipFile );

            ((XLSParserImpl)parser).setHeaderRowIdx(0);
            ((XLSParserImpl)parser).setDataStartRowIdx(1);

            result = parser.parse();

            //System.out.println("result.getString() = " + result.getHeadings() );

            while ( result.next() )
            {
                partNumber   = result.getString("DEVICE_TYPE");
                fablotNumber = result.getString("LOT_NO");
                lotNumber    = result.getString("SCHEDULE_NO");
                if ( lotNumber == null)
                {
                    lotNumber = fablotNumber;
                }

                if ( partNumber != null && partNumber.length() > 0 && lotNumber != null && lotNumber.length() > 0 )
                {
                    if ( !"W".equalsIgnoreCase(result.getString("MATERIAL_TYPE") ) )
                    {
                        testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fablotNumber );
                        if (testLot == null)
                        {
                            testLot = new TestLot(VENDOR_NAME_ASET);
                            m_ftDataMap.put(partNumber + lotNumber + fablotNumber, testLot);
                        }
                        int quantity = 0;
                        if( testLot.getQtyIn() != null )
                        {
                            try
                            {
                                quantity = Integer.parseInt( testLot.getQtyIn() );
                            }
                            catch(NumberFormatException e)
                            {
                                quantity = result.getInt("CURRENT_QTY");
                            }
                            quantity +=result.getInt("CURRENT_QTY");
                         }
                         else
                         {
                            quantity =result.getInt("CURRENT_QTY");
                         }
                        if ( quantity > 0 )
                        {
                            testLot.setPartNumber( partNumber );
                            testLot.setLotNumber( lotNumber );
                            testLot.setFabLotNumber( fablotNumber );
                            testLot.setQtyIn( quantity +"");
                            testLot.setDateIn( StringUtils.formatDate(result.getString("INIT_DATE"), "yyyyMMddHHmmss", "MM/dd/yyyy HH:mm:ss" ));
                            testLot.setStatus(LOT_STATUS_HOLD);
                            testLot.setPsType( LOCATION_TYPE_FT );
                            testLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                        }
                    }
                    else
                    {
                        sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fablotNumber );
                        if (sortLot == null)
                        {
                            sortLot = new FabSortLot( VENDOR_NAME_ASET, WIP_TYPE_SORT );
                            m_sortDataMap.put( partNumber + fablotNumber, sortLot);
                        }
                        int wquantity = 0;
                        if( sortLot.getQtyIn() != null )
                        {
                            try
                            {
                                wquantity = Integer.parseInt( sortLot.getQtyIn() );
                            }
                            catch(NumberFormatException e)
                            {
                                wquantity = result.getInt("CURRENT_QTY");
                            }
                            wquantity +=result.getInt("CURRENT_QTY");
                         }
                         else
                         {
                            wquantity =result.getInt("CURRENT_QTY");
                         }
                        if ( wquantity > 0 )
                        {
                            sortLot.setLotId( fablotNumber );
                            sortLot.setCustProduct( partNumber );
                            sortLot.setFabLotNumber( fablotNumber );
                            sortLot.setQtyIn( wquantity+"");
                            sortLot.setLotCategory ( LOT_CATEGORY_TYPE_PROD );
                            sortLot.setDateIn( StringUtils.formatDate(result.getString("INIT_DATE"), "yyyyMMddHHmmss", "MM/dd/yyyy HH:mm:ss" ));
                            sortLot.setLotStatus( LOT_STATUS_HOLD );
                        }
                    }
                }
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET FT Hold Report");
            ex.printStackTrace();
            throw ex;
        }
    }

    private ArrayList<TestLotBinReport> parseFTBinReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );
        ParserResult result     = null;

        String lotNumber        = null;
        String partNumber       = null;
        String fablotNumber     = null;
        ArrayList<TestLotBinReport> ftYieldList  = new ArrayList<TestLotBinReport>();

        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for Ft Yield Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for FT Yield Report..." );

            Parser parser = ParserFactory.getXLSParser( detailWipFile );

            ((XLSParserImpl)parser).setHeaderRowIdx(2);
            ((XLSParserImpl)parser).setDataStartRowIdx(3);

            result = parser.parse();

            //System.out.println("result.getString() = " + result.getHeadings() );

            while ( result.next() )
            {
                partNumber   = result.getString("DEVICE");
                fablotNumber = result.getString("Ikanons Lot No");
                lotNumber    = result.getString("Subcon Lot No");
                if ( lotNumber == null)
                {
                    lotNumber = fablotNumber;
                }

                if ( partNumber != null && partNumber.length() > 0 && lotNumber != null && lotNumber.length() > 0 )
                {
                    TestLotBinReport ftYieldStatus = new TestLotBinReport();

                    ftYieldStatus.setDeviceName( partNumber );
                    ftYieldStatus.setLotNumber( lotNumber );
                    ftYieldStatus.setCustLotNo( fablotNumber );
                    //ftYieldStatus.setPoNumber( result.getString("Release No"));
                    ftYieldStatus.setPkgType( result.getString("Package") );
                    ftYieldStatus.setLeadCount( result.getString("L/C") );
                    ftYieldStatus.setStage( result.getString("INSERTION") ); // Insertion
                    ftYieldStatus.setTestProg(result.getString("Program No"));
                    ftYieldStatus.setTesterId( result.getString("Tester ID") );
                    ftYieldStatus.setDateCode( result.getString("Date Code") );
                    ftYieldStatus.setHandler( result.getString("Handler ID") );
                    ftYieldStatus.setLb(result.getString("L/B ID"));
                    ftYieldStatus.setTemp( result.getString("Temp"));
                    ftYieldStatus.setDateIn( StringUtils.formatDate( result.getString("Test In Date"),"yyyy/MM/dd HH:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                    ftYieldStatus.setDateOut(StringUtils.formatDate( result.getString("Test Out Date"),"yyyy/MM/dd HH:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                    ftYieldStatus.setInQty( result.getInt("In Qty") +"");
                    ftYieldStatus.setPassQty( result.getInt("Out Qty")+"" );
                    //ftYieldStatus.setDamageQty( result.getString("Defect Qty") );
                    ftYieldStatus.setYield( result.getString("Yield").replaceAll("%",""));
                    ftYieldStatus.setBin1( result.getString("Bin 1") );
                    ftYieldStatus.setBin2(result.getString("Bin 2"));
                    ftYieldStatus.setBin3(result.getString("Bin 3"));
                    ftYieldStatus.setBin4(result.getString("Bin 4"));
                    ftYieldStatus.setBin5(result.getString("Bin 5"));
                    ftYieldStatus.setBin6(result.getString("Bin 6"));
                    ftYieldStatus.setBin7(result.getString("Bin 7"));
                    ftYieldStatus.setBin8(result.getString("Bin 8"));

                    ftYieldStatus.setLossQty( result.getString("Loss QTY") );
                    ftYieldStatus.setVmQty( result.getString("VM QTY") );
                    ftYieldStatus.setOsQty( result.getString("OS QTY") );

                    ftYieldList.add( ftYieldStatus );

                }
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET FT Yield Report");
            ex.printStackTrace();
            throw ex;
        }

        return ftYieldList;
    }

    private ArrayList<SortLotBinData> parseCPBinReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );
        ParserResult result     = null;

        String lotNumber        = null;
        String partNumber       = null;
        String fablotNumber     = null;
        FabSortLot sortBinTotalLot = null;
        FabSortLot sortBinLot   = null;
        ArrayList<SortLotBinData> cpYieldList  = new ArrayList<SortLotBinData>();
        int waferId             = 0;
        HashMap waferIdMap = new HashMap();
        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for CP Yield Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for CP Yield Report..." );

            Parser parser = ParserFactory.getXLSParser( detailWipFile, "WS" );

            ((XLSParserImpl)parser).setHeaderRowIdx(2);
            ((XLSParserImpl)parser).setDataStartRowIdx(3);

            result = parser.parse();

            //System.out.println("result.getString() = " + result.getHeadings() );
             while ( result.next() )
            {
                partNumber = result.getString("Device");
                lotNumber = result.getString("Wafer Lot No");
                waferId   = result.getInt("Wafer #");

                if (partNumber!= null && partNumber.trim().length()>0 && lotNumber != null && lotNumber.trim().length() > 0 && waferId > 0 && waferId < 26 )
                {
                    sortBinTotalLot = (FabSortLot) m_sortTotalMap.get( partNumber + lotNumber);

                    if ( sortBinTotalLot == null )
                    {
                        sortBinTotalLot = new FabSortLot( VENDOR_NAME_ASET, LOCATION_TYPE_SORT );
                        m_sortTotalMap.put( partNumber + lotNumber  , sortBinTotalLot );
                    }
                    int m_totalProbeQty         = 0;
                    int m_totalPassQty          = 0;
                    int m_waferQtyIn            = 0;
                    if ( sortBinTotalLot.getQtyIn() != null )
                    {

                        try
                       {
                           m_waferQtyIn = Integer.parseInt( sortBinTotalLot.getQtyIn() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                       }

                       m_totalPassQty = sortBinTotalLot.getTotalgoodDieQtyIn();
                       m_totalProbeQty = sortBinTotalLot.getTotalprobeQtyIn();

                       if ( !waferIdMap.containsKey( partNumber + lotNumber + waferId ) )
                       {
                           waferIdMap.put( partNumber + lotNumber+waferId, waferId );

                           m_waferQtyIn += 1;
                           m_totalPassQty += result.getInt("Good Dies");
                           m_totalProbeQty += result.getInt("GDPW");
                       }
                    }
                    else
                    {
                        if ( !waferIdMap.containsKey( partNumber + lotNumber+waferId ) )
                        {
                            waferIdMap.put( partNumber + lotNumber+waferId, waferId );
                            m_waferQtyIn = 1;
                            m_totalPassQty = result.getInt("Good Dies");
                            m_totalProbeQty = result.getInt("GDPW");
                        }
                     }
                     sortBinTotalLot.setQtyIn( m_waferQtyIn+"");
                     sortBinTotalLot.setTotalgoodDieQtyIn( m_totalPassQty);
                     sortBinTotalLot.setTotalprobeQtyIn( m_totalProbeQty );
                }
            }
            //FOR Restting the Row Index
            result.reset();

            while ( result.next() )
            {
                partNumber   = result.getString("Device");
                fablotNumber = result.getString("Wafer Lot No");
                /*lotNumber    = result.getString("Subcon Lot No");*/
                if ( lotNumber == null)
                {
                    lotNumber = fablotNumber;
                }
                waferId   = result.getInt("Wafer #");
                if ( partNumber != null && partNumber.length() > 0 && lotNumber != null && lotNumber.length() > 0 && waferId > 0 && waferId < 26 )
                {
                    SortLotBinData cpYieldStatus = new SortLotBinData();

                    sortBinLot = ( FabSortLot ) m_sortBinDataMap.get( partNumber + fablotNumber + waferId);

                    if ( sortBinLot == null )
                    {
                        sortBinLot = new FabSortLot( VENDOR_NAME_ASET, LOCATION_TYPE_SORT );
                        m_sortBinDataMap.put( partNumber + fablotNumber + waferId  , sortBinLot );
                    }
                    sortBinLot.setCustProduct( partNumber );
                    sortBinLot.setLotId( fablotNumber );
                    sortBinLot.setFabLotNumber( fablotNumber );
                    sortBinLot.setWaferID( waferId+"" );
                     // WAFER QTY IN Always Same(total wafers) ,But For Each every Wafer update the Wafer Qty, the the WaferQty
                    sortBinLot.setQtyIn( m_sortTotalMap.get(partNumber + fablotNumber).getQtyIn() +"");
                    sortBinLot.setTotalgoodDieQtyIn( m_sortTotalMap.get(partNumber + fablotNumber).getTotalgoodDieQtyIn() );
                    sortBinLot.setTotalprobeQtyIn( m_sortTotalMap.get(partNumber + fablotNumber).getTotalprobeQtyIn() );
                    sortBinLot.setDateOut( StringUtils.formatDate(result.getString("Test Out Date"), "yyyy/MM/dd HH:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                    sortBinLot.setDateIn( StringUtils.formatDate(result.getString("Test In Date"),"yyyy/MM/dd HH:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                    sortBinLot.setTesterNo( result.getString("Tester ID") );
                    sortBinLot.setTestProgram( result.getString("Program No") );
                    sortBinLot.setGoodDieQtyIn(result.getInt("Good Dies"));
                    sortBinLot.setRejectedQtyIn(result.getInt("GDPW")-result.getInt("Good Dies"));
                    sortBinLot.setShipYield(result.getString("Yield").replaceAll("%","") );
                    sortBinLot.setTotalYield( 0 ); // if sets as 0, in the PROC Yield Calculating (INQTY *100.00/OUTQTY)
                    sortBinLot.setBinNumber( "Bin1" );

                    cpYieldStatus.setProduct( partNumber );
                    cpYieldStatus.setLotNumber(fablotNumber );
                    cpYieldStatus.setFablotNumber( fablotNumber );
                    cpYieldStatus.setTemp(result.getString("Temperature"));
                    cpYieldStatus.setProbeId(result.getString("Prober ID"));
                    cpYieldStatus.setProbeCard(result.getString("Probe Card"));
                    cpYieldStatus.setInsertion(result.getString("Insertion"));
                    cpYieldStatus.setGrossDice( result.getInt("GDPW")+"");
                    cpYieldStatus.setGoodDice( result.getInt("Good Dies")+"");
                    cpYieldStatus.setShipYield( result.getString("Yield").replaceAll("%","") );
                    cpYieldStatus.setWaferId( waferId+"");
                    cpYieldStatus.setDateIn( StringUtils.formatDate(result.getString("Test In Date"), "yyyy/MM/dd HH:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                    int[] binQty = new int[100];
                    int binNo = 0;
                    for(int i=1; i<=100; i++ )
                    {
                        binQty[binNo++] = result.getInt("Bin "+i);
                    }

                    cpYieldStatus.setBinQty( binQty );
                    cpYieldList.add( cpYieldStatus );

                }
            }
        }
        catch ( Exception ex )
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the ASET CP Yield Report");
            ex.printStackTrace();
            throw ex;
        }

        return cpYieldList;
    }
    private void log( String message )
    {
        if ( message == null ) return;

        if ( m_parserLogger != null )
        {
            m_parserLogger.logDebug( message + LINE_SEPARATOR );
        }
        else
        {
            System.out.println( message );
        }
    } // end of log method
}
